<#compress>
<!DOCTYPE html>
<html>
  <head>
    <title>文章编辑</title>
    <meta name="content-type" content="text/html; charset=UTF-8">
  <link href="//cdn.bootcss.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
  <link href="${webroot}/www/admin/css/page-main.css" rel="stylesheet">
  <script src="//cdn.bootcss.com/jquery/2.2.0/jquery.min.js"></script>
  <script src="//cdn.bootcss.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
  <link href="//cdn.bootcss.com/limonte-sweetalert2/6.4.2/sweetalert2.min.css" rel="stylesheet">
  <script src="//cdn.bootcss.com/limonte-sweetalert2/6.4.2/sweetalert2.min.js"></script>
  <script type="text/javascript" src="http://${host}/www/admin/js/blog.js"></script>
  <script src="${webroot}/www/blog/js/pub/blog-alert.js"></script>
	<link href="//cdn.bootcss.com/bootstrap-switch/3.3.4/css/bootstrap3/bootstrap-switch.min.css" rel="stylesheet">
	<script src="//cdn.bootcss.com/bootstrap-switch/3.3.4/js/bootstrap-switch.min.js"></script>
	<!-- ueditor -->
	<script type="text/javascript" charset="utf-8" src="${webroot}/www/ueditor/ueditor.config.js"></script>
	  <script type="text/javascript" charset="utf-8" src="http://apps.bdimg.com/libs/ueditor/1.4.3.1/ueditor.all.js"> </script>

    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="${webroot}/www/ueditor/lang/zh-cn/zh-cn.js"></script>
	  <link href="//cdn.bootcss.com/bootstrap-tokenfield/0.12.0/css/bootstrap-tokenfield.min.css" rel="stylesheet">
	  <script src="//cdn.bootcss.com/bootstrap-tokenfield/0.12.0/bootstrap-tokenfield.min.js"></script>
	  <script type="text/javascript" charset="utf-8" src="${webroot}/www/admin/js/edit_article.js"></script>

    <style type="text/css">
		body{height:100%; overflow:hidden; margin:0px; padding:0px;}
		.box {height:90%; position:absolute; width:98%;}
        .lable_css{
        	font-family: 微软雅黑;
        	font-weight: bold;
        	cursor: pointer;
        }
    </style>
  </head>
  <body >
  <#include "/admin/include/dashboard-start.ftl">
	  <form class="form-horizontal" method="post" action="${admin_blogprefix}/admin/save_article.do" id="ar_editform">
		  <div class="form-group">
			  <div class="col-sm-10">
				  <input type="hidden" name="id" value="${article.id!}"/>
				  <input type="hidden" name="articleEditor" value="html"/>
				  <input type="hidden" name="articleCover" id="articleCover" value="${article.articleCover!}" >
				  <input type="text" class="form-control" name="articleTitle" placeholder="请输入文章标题" value="${article.articleTitle!}" maxlength="100">
			  </div>
			  <button type="button" class="btn btn-default" onclick="Article.AdvancedMode(this);">高级</button>
			  <#if article??&&article.id??>
				  <a href="${admin_blogprefix}/${AdminWebSite.websiteName}/entry/${article.id}.html" target="_blank" class="sbtn sbtn-purple" >预览</a>
			  </#if>
			  <button type="button" class="sbtn sbtn-green" onclick="submitFun();">保存</button>
		  </div>
		  <div class="form-group">
			  <div class="col-sm-12">
				  <@Category website_id="${AdminWebSite.id}">
				  <#list category_lis as category>
					  <label class="radio-inline">
						  <input type="radio" name="category.id"  value="${category.id}"
						  <#if article.category??>
							  <#if category.id==article.category.id>
								  checked="checked"
							  </#if>
							  <#elseif category_has_next==false>
								  checked="checked"
						  </#if> > ${category.categoryName}
					  </label>
				  </#list>
			  </@Category>
		  </div>
		  </div>
		  <div class="form-group">
			  <div class="col-sm-12">
				  <input type="text" class="form-control" name="articleLableStr" id="lables" placeholder="标签 (最多4个,已逗号分隔)"   />
			  </div>
		  </div>
		  <div class="form-group" id="div_summary" style="display: none;">
			  <div class="col-sm-12">
				  <textarea class="form-control" rows="4" name="articleSummary" maxlength="400">${article.articleSummary!}</textarea>
			  </div>
		  </div>
		  <div class="box">
			  <input type="hidden" name="articleContent" id="ar_content"/>
			  <script id="editor" type="text/plain"  >${article.articleContent!}</script>
			  <p></p>
			  <div style="float: left;">
				  <strong>允许评论：</strong> <input type="checkbox" name="articleAllowcomments" value="true" <#if article.articleAllowcomments>checked</#if> />
				  <strong>私密文章：</strong><input type="checkbox" name="articlePrivate" value="true" <#if article??&&article.articlePrivate>checked</#if> />
				  <#if article??&&article.id??>
					  <strong>是否发布：</strong><input type="checkbox" name="type" value="release"/>
				  </#if>
			  </div>
			  <div style="float: left;padding-left: 20px;">
				  <input type="text" class="form-control" name="articlePassword" style="width: 200px;" maxlength="10" placeholder="查看密码,私密博文下无效" value="${article.articlePassword!}">
			  </div>
		  </div>
	  </form>
  <#include "/admin/include/dashboard-end.ftl">
  </body>
  <script type="text/javascript">
	  blogControlPanel.activePanelByText("发布文章");
	  $(":checkbox").bootstrapSwitch({size:'small',onColor:'success',offColor:'danger',onText:'开启',offText:'关闭'});
  /*(function(){
	    // 关闭窗口时弹出确认提示
	    $(window).bind('beforeunload', function(){
	        // 只有在标识变量is_confirm不为false时，才弹出确认提示
	        if(window.is_confirm !== false)
	            return '您可能有数据没有保存';
	    })
	    // mouseleave mouseover事件也可以注册在body、外层容器等元素上
	    .bind('mouseover mouseleave', function(event){
	        is_confirm = event.type == 'mouseleave';
	    });
	})();*/

 //ueditor
	  var height=parseInt($(".box").height())-200;
  var ue = UE.getEditor('editor', { wordCount:false,initialFrameHeight:height,
	  toolbars: [
		  [
			  'anchor', //锚点
			  'bold', //加粗
			  'italic', //斜体
			  'underline', //下划线
			  'strikethrough', //删除线
			  'blockquote', //引用
			  'fontsize', //字号
			  'paragraph', //段落格式
			  'forecolor', //字体颜色
			  'justifyleft', //居左对齐
			  'justifyright', //居右对齐
			  'justifycenter', //居中对齐
			  'justifyjustify', //两端对齐
			  'insertorderedlist', //有序列表
			  'insertunorderedlist', //无序列表
			  'pasteplain', //纯文本粘贴模式
			  'horizontal', //分隔线
			  'removeformat', //清除格式
			  'simpleupload', //单图上传
			  'insertimage', //多图上传
			  'attachment', //附件
			  'wordimage', //图片转存
			  'link', //超链接
			  'spechars', //特殊字符
			  'searchreplace', //查询替换
			  'fullscreen', //全屏
			  'lineheight', //行间距
			  'edittip ', //编辑提示
			  'autotypeset', //自动排版
			  'inserttable', //插入表格
			  'insertcode', //代码语言
			  'source', //源代码
			  'preview' //预览
		  ]
	  ]
  });

   ue.addListener('contentChange',function(){
	   setcontent();
	 })
 
 function setcontent(){
	// 获取编辑器区域完整html代码
	     var html = ue.getContent();//editor.$txt.html();
		$("#ar_content").val(html);
   }


	  window.onload=function(){
		  $('#lables').tokenfield({limit:4})
				  .on('tokenfield:removedtoken', function (e) {
					  if(e.attrs.value.length==32){
						  bootbox.confirm({
							  message: "<b style='color:red;'>是否删除此标签?</b>",
							  size: 'small',
							  buttons: {
								  confirm: {
									  label: '是',
									  className: 'btn-success'
								  },
								  cancel: {
									  label: '否',
									  className: 'btn-danger'
								  }
							  },
							  callback: function (result) {
								  if(result){
									  $.ajax({
										  type: "get",
										  url: "${admin_blogprefix}/admin/del_article_lable.do",
										  data: {id:e.attrs.value},
										  success: function(msg){
											  if(msg=="success"){

											  }else{
												  alert( msg);
											  }
										  }
									  });
								  }
							  }
						  });
					  }
				  });
		  <#if article??&&article.id!=''> $('#lables').tokenfield('setTokens', [<#list article.lables as lable>{ value: '${lable.id}', label: '${lable.lableName}'}<#if lable_has_next>,</#if></#list>]);</#if>
	  };
function submitFun(){
	var title=$("input[name='articleTitle']").val().trim();
	if(title==""||title.length<5){
		blogAlert.error("","文章标题不能为空，并且不得少于5个字符！");
	}else if(ue.getContent().length<50){
		blogAlert.error("","文章html内容不能为空，并且不得少于50个字符！");
	}else{
		$("#ar_editform").submit();
	}
}
</script> 
</html>
</#compress>